*	************************************************************************
* 	File-Name: 	Replication.do
*	Log-file:	na
*	Date:  		06/23/2019
*	Author: 	Jennifer Richmond and Johannes Urpelainen
*	Data Used:  appliances.dta
*	Output		na
*	Purpose:   	.do file to replicate the findings in Electrification and 
*					Appliance Ownership Over Time: Evidence from Rural India
*	************************************************************************

set more off, perm
capture log close
clear all
set type double

*	************************************************************************
*	0. Setting up the data
*	************************************************************************

* Change this file path to the working directory where the dataset is located
use "C:/Users/Jen/Dropbox/Appliances (Richmond-Urpelainen)/Richmond-Urpelainen Dataverse/appliances.dta", clear
* Change this file path to your working directory where you want to work throughout this file
cd "C:/Users/Jen/Dropbox/Appliances (Richmond-Urpelainen)/Richmond-Urpelainen Dataverse"
* Denoting survey set data
svyset [pweight=weight], strata(m1_q11_village_code) singleunit(centered) 
xtset m1_q11_village_code 

*	************************************************************************
* 	1. Summary statistics
*	************************************************************************

* TABLE 2 : SUMMARY STATISTICS 

estpost sum highest_tier phone cfl fan pressure tvs fridge m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children expend100	nl_expend baseline_edu higher_edu hindu scheduled_caste distance nl_distance
esttab, cell((count(label(N)) mean(label(Mean) fmt(2)) sd(label(Std. Dev.) fmt(2)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)))) title("Summary statistics") label nomtitle nonumber varwidth(25) booktabs noobs replace	
	
*  ****************************************************************************
*  2. Main analysis
*  ****************************************************************************

* TABLE 3 : OLS MODELS WITH HIGHEST TIER REACHED AS ORDINAL DEPENDENT VARIABLE

eststo: svy: reg highest_tier m2_q55_1_grid_years, noconstant
estimates store reg1	
eststo: xi: svy: reg highest_tier m2_q55_1_grid_years i.m1_q8_state_code, noconstant 
estimates store reg2
eststo: xi: svy: reg highest_tier m2_q55_1_grid_years i.m1_q9_district_code, noconstant 
estimates store reg3
eststo: xi: svy: reg highest_tier m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q8_state_code, noconstant 
testparm m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q8_state_code, equal
estimates store reg4
testparm m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q9_district_code, equal
estimates store reg5	 
testparm m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q8_state_code, equal
estimates store reg6	
testparm m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district_code, equal
estimates store reg7
esttab reg2 reg3 reg4 reg5 reg6 reg7, replace nomtitles label starlevels(* 0.10 ** 0.05 *** 0.01) booktabs stats(N r2) se drop(_Im1_q8_sta_* _Im1_q9_dis_*) depvars b(3) se(3)

* TABLE 4 : POISSON MODELS WITH TOTAL HOUSEHOLD APPLIANCE COUNT AS DEPENDENT VARIABLE

eststo: svy: poisson totalapp m2_q55_1_grid_years i.m1_q8_state_code, eform
estimates store reg2p
eststo: svy: poisson totalapp m2_q55_1_grid_years i.m1_q9_district_code, eform
estimates store reg3p 
eststo: svy: poisson totalapp m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q8_state_code, eform
estimates store reg4p
eststo: svy: poisson totalapp m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q9_district_code, eform
estimates store reg5p 
eststo: svy: poisson totalapp m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q8_state_code, eform
estimates store reg6p
eststo: svy: poisson totalapp m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district_code, eform
estimates store reg7p
esttab reg2p reg3p reg4p reg5p reg6p reg7p, replace nomtitles label starlevels(* 0.10 ** 0.05 *** 0.01) booktabs stats(N) se nodepvars drop(1* 2* 3* 4* *state*) b(3) se(3) eform

* TABLE 5 : PREFERRED OLS MODELS WITH DISTRICT FIXED EFFECTS AND APPLIANCE DUMMY DEPENDENT VARIABLES

eststo: xi: svy: reg phone m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district, noconstant
estimates store regapp1
eststo: xi: svy: reg cfl m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q9_district, noconstant 
estimates store regapp2
eststo: xi: svy: reg fan m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q9_district, noconstant  
estimates store regapp3
eststo: xi: svy: reg pressure m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district, noconstant 
estimates store regapp4
eststo: xi: svy: reg tvs m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q9_district, noconstant 
estimates store regapp5
eststo: xi: svy: reg fridge m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district, noconstant 
estimates store regapp6
esttab regapp1 regapp2 regapp3 regapp4 regapp5 regapp6, replace label starlevels(* 0.10 ** 0.05 *** 0.01) booktabs stats(N r2) se nodepvars drop(*_dis_*) mtitles("Phone" "CFL" "Fan" "Cooker" "TV" "Fridge") b(3) se(3)

* TESTS FOR MULTICOLLINEARITY AMONG MAIN REGRESSION VARIABLES

eststo: xi: svy: reg hindu highest_tier m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu scheduled_caste nl_distance i.m1_q9_district_code
display "tolerance = " 1-e(r2) " VIF = " 1/(1-e(r2))
eststo: xi: svy: reg scheduled_caste highest_tier m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu nl_distance i.m1_q9_district_code
display "tolerance = " 1-e(r2) " VIF = " 1/(1-e(r2))
eststo: xi: svy: reg  m2_q55_1_grid_years highest_tier decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu nl_distance scheduled_caste i.m1_q9_district_code
display "tolerance = " 1-e(r2) " VIF = " 1/(1-e(r2))
eststo: xi: svy: reg decision_f m2_q55_1_grid_years highest_tier m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu nl_distance scheduled_caste i.m1_q9_district_code
display "tolerance = " 1-e(r2) " VIF = " 1/(1-e(r2))
eststo: xi: svy: reg m1_q27_no_adults decision_f m2_q55_1_grid_years highest_tier m1_q29_no_children nl_expend baseline_edu higher_edu hindu nl_distance scheduled_caste i.m1_q9_district_code
display "tolerance = " 1-e(r2) " VIF = " 1/(1-e(r2))
eststo: xi: svy: reg m1_q29_no_children m1_q27_no_adults decision_f m2_q55_1_grid_years highest_tier nl_expend baseline_edu higher_edu hindu nl_distance scheduled_caste i.m1_q9_district_code
display "tolerance = " 1-e(r2) " VIF = " 1/(1-e(r2))
eststo: xi: svy: reg nl_expend m1_q29_no_children m1_q27_no_adults decision_f m2_q55_1_grid_years highest_tier baseline_edu higher_edu hindu nl_distance scheduled_caste i.m1_q9_district_code
display "tolerance = " 1-e(r2) " VIF = " 1/(1-e(r2))

*	************************************************************************
* 	3. Appendix analysis
*	************************************************************************

* TABLE A1 : ORDERED LOGIT MODELS WITH HIGHEST TIER ACHIEVED AS ORDINAL DEPENDENT VARIABLE

eststo: svy: ologit highest_tier m2_q55_1_grid_years i.m1_q8_state_code, or allbaselevels
estimates store logit1	
eststo: svy: ologit highest_tier m2_q55_1_grid_years i.m1_q9_district_code, or allbaselevels
estimates store logit2
eststo: svy: ologit highest_tier m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q8_state_code, or allbaselevels
estimates store logit3
eststo: svy: ologit highest_tier m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q9_district_code, or allbaselevels
estimates store logit4
eststo: svy: ologit highest_tier m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q8_state_code, or allbaselevels
estimates store logit5
eststo: svy: ologit highest_tier m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q9_district_code, or allbaselevels 
estimates store logit6
esttab logit1 logit2 logit3 logit4 logit5 logit6, replace nomtitles label starlevels(* 0.10 ** 0.05 *** 0.01) booktabs stats(N) se eform drop(1* 2* 3* 4* 9* cut*) nodepvars b(3) se(3)

* TABLE A2 : OLS MODELS WITH STATE FIXED EFFECTS

eststo: xi: svy: reg phone m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q8_state_code 
estimates store regapps1
eststo: xi: svy: reg cfl m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q8_state_code 
estimates store regapps2
eststo: xi: svy: reg fan m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q8_state_code 
estimates store regapps3
eststo: xi: svy: reg pressure m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q8_state_code 
estimates store regapps4
eststo: xi: svy: reg tvs m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q8_state_code 
estimates store regapps5
eststo: xi: svy: reg fridge m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q8_state_code
estimates store regapps6
esttab regapps1 regapps2 regapps3 regapps4 regapps5 regapps6, replace label starlevels(* 0.10 ** 0.05 *** 0.01) booktabs stats(N r2) se nodepvars drop(*_sta_*) mtitles("Phone" "CFL" "Fan" "Cooker" "TV" "Fridge") b(3) se(3)

* TABLE A3 : OLS MODELS WITH HIGHEST TIER REACHED AS DEPENDENT VARIABLE AND RESTRICTED SAMPLE SIZE

eststo: xi: svy: reg highest_tier m2_q55_1_grid_years i.m1_q8_state_code 
estimates store reg2
eststo: xi: svy: reg highest_tier m2_q55_1_grid_years i.m1_q9_district_code 
estimates store reg3
eststo: xi: svy: reg highest_tier m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q8_state_code
testparm m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q8_state_code, equal
estimates store reg4
eststo: xi: svy: reg highest_tier m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q9_district_code
testparm m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q9_district_code, equal
estimates store reg5
eststo: xi: svy: reg highest_tier m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q8_state_code	
testparm m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q8_state_code, equal
estimates store reg6
eststo: xi: svy: reg highest_tier m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district_code
testparm m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district_code, equal
corr highest_tier m1_q32_month_expenditure nl_expend hindu scheduled_caste
estimates store reg7
esttab reg2 reg3 reg4 reg5 reg6 reg7, replace nomtitles label starlevels(* 0.10 ** 0.05 *** 0.01) booktabs stats(N r2) se drop(_Im1_q8_sta_* _Im1_q9_dis_*) depvars b(3) se(3)

* TABLE A4 : POISSON MODELS WITH TOTAL COUNT OF APPLIANCES AS DEPENDENT VARIABLE AND RESTRICTED SAMPLE SIZE

eststo: svy: poisson totalapp m2_q55_1_grid_years i.m1_q8_state_code, eform
estimates store reg2p
eststo: svy: poisson totalapp m2_q55_1_grid_years i.m1_q9_district_code, eform
estimates store reg3p 
eststo: svy: poisson totalapp m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q8_state_code, eform
testparm m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q8_state_code, equal
estimates store reg4p
eststo: svy: poisson totalapp m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q9_district_code, eform
testparm m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu i.m1_q9_district_code, equal
estimates store reg5p 
eststo: svy: poisson totalapp m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q8_state_code, eform
testparm m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q8_state_code, equal
estimates store reg6p
eststo: svy: poisson totalapp m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district_code, eform
testparm m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district_code, equal
estimates store reg7p
esttab reg2p reg3p reg4p reg5p reg6p reg7p, replace nomtitles label starlevels(* 0.10 ** 0.05 *** 0.01) booktabs stats(N) se nodepvars drop(1* 2* 3* 4* *state*) b(3) se(3) eform
	
* TABLE A5 : OLS MODELS WITH DISTRICT FIXED EFFECTS FOR KEY APPLIANCE DUMMY DEPENDENT VARIABLES AND A RESTRICTED SAMPLE SIZE

eststo: xi: svy: reg phone m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district_code
estimates store regapp1
eststo: xi: svy: reg cfl m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q9_district 
corr cfl hindu scheduled_caste
estimates store regapp2
eststo: xi: svy: reg fan m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q9_district 
estimates store regapp3
eststo: xi: svy: reg pressure m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district
estimates store regapp4
eststo: xi: svy: reg tvs m2_q55_1_grid_years decision_f	m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu	scheduled_caste nl_distance i.m1_q9_district 
estimates store regapp5
eststo: xi: svy: reg fridge m2_q55_1_grid_years decision_f m1_q27_no_adults m1_q29_no_children nl_expend baseline_edu higher_edu hindu scheduled_caste nl_distance i.m1_q9_district 
estimates store regapp6
esttab regapp1 regapp2 regapp3 regapp4 regapp5 regapp6, replace label starlevels(* 0.10 ** 0.05 *** 0.01) booktabs stats(N r2) se nodepvars drop(*_dis_*) mtitles("Phone" "CFL" "Fan" "Cooker" "TV" "Fridge") b(3) se(3)
	
*	************************************************************************
* 	3. Main text figures
*	************************************************************************

* FIGURE 1 : AVERAGE HOUSEHOLD APPLIANCE OWNERSHIP BY TIER AND STATE 

preserve //Adding data below that is then dropped by the restore command below
set obs 5116 //Adding calculated totals to the dataset to construct a totaled top bar for this graph
replace m1_q8_state = "ALL STATES" in 5116
replace tier1 = 2.80 in 5116
replace tier2 = 1.02 in 5116
replace tier3 = .14 in 5116
replace tier4 = .22 in 5116
graph hbar tier1 tier2 tier3 tier4, over(m1_q8_state, gap(130) axis(lcolor(gray)) label(labsize(small) labcolor(gray) tlcolor(gray))) bar(1, color("174 225 234")) bar(2, color("239 221 160"))	bar(3, color("123 196 188")) bar(4, color("205 204 203")) graphregion(fcolor(white) color(white) lcolor(white)) plotregion(lcolor(white)) legend(lab(1 "Tier 1") lab(2 "Tier 2") lab(3 "Tier 3") lab(4 "Tier 4") color(gray)) ylabel(, nogrid labcolor(gray) tlcolor(gray)) ytitle("Number of household appliances (average by state)", color(gray) size(small)) legend(region(lcolor(white))) yscale(lcolor(gray)) bargap(10) legend(size(small)) title("Average household appliance ownership by tier and state", color(gray) size(medium))	
graph export, replace
restore

* FIGURE 2 : DISTRIBUTION OF NUMBER OF YEARS OF ELECTRICITY ACCESS

hist m2_q55_1_grid_years, color("146 196 233") lcolor(white) percent w(3) graphregion(fcolor(white)color(white)) ylabel(,nogrid labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) yscale(lcolor(gray)) xscale(lcolor(gray)) ytitle(,color(gray)) xtitle(,color(gray)) title("Distribution of number of years of electricity access", color(gray))
graph export, replace	

* FIGURE 3 : HOUSEHOLD APPLIANCE COUNT AND YEARS OF ELECTRIFICATION (BY VILLAGE)

twoway sc totalappmeanv grid_meanyrsv, mcolor("179 221 232") graphregion(c(white)) title("Household appliance count and years of electrification (by village)", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("Years of electrification (average by village)", c(gray) size(small)) ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("Number of household appliances (average by village)") legend(off) || lfit totalappmeanv grid_meanyrsv, lc(gs12)
graph export, replace

* FIGURE 4 : TIERED APPLIANCE OWNERSHIP AND YEARS SINCE ELECTRIFICATION BY VILLAGE

twoway sc tier1mean grid_meanyrsv, mcolor("249 198 159") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray)) title("Tier 1", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("")/*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 1 appliances (mean by village)")*/ legend(off) || lfit tier1mean grid_meanyrsv, lc(gs12) saving(tier1, replace)
twoway sc tier2mean grid_meanyrsv, mcolor("249 198 159") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray)) title("Tier 2", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("") /*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 2 appliances (mean by village)")*/ legend(off) || lfit tier2mean grid_meanyrsv, lc(gs12) saving(tier2, replace)
twoway sc tier3mean grid_meanyrsv, mcolor("249 198 159") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray)) title("Tier 3", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("") /*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 3 appliances (mean by village)")*/ legend(off) || lfit tier3mean grid_meanyrsv, lc(gs12) saving(tier3, replace)
twoway sc tier4mean grid_meanyrsv, mcolor("249 198 159") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray)) title("Tier 4", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("") /*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 4 appliances (mean by village)")*/ legend(off) || lfit tier4mean grid_meanyrsv, lc(gs12) saving(tier4, replace)
graph combine tier1.gph tier2.gph tier3.gph tier4.gph, xcommon ycommon title("Tiered appliance ownership and years since electrification by village", size(medium) c(gray)) graphregion(c(white)) l1("Number of household appliances (average by village)", size(small) color(gray)) b1("Years since electrification (average by village)", size(small) color(gray))
graph export, replace

* FIGURE 5 : OWNERSHIP OF KEY APPLIANCES AND YEARS SINCE ELECTRIFICATION BY VILLAGE

twoway sc phone_mean grid_meanyrsv, mcolor("176 227 202") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray) range(1)) title("Phones", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("") /*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 2 appliances (mean by village)")*/ legend(off) || lfit phone_mean grid_meanyrsv, lc(gs12) saving(phone_mean, replace)
twoway sc cfl_mean grid_meanyrsv, mcolor("176 227 202") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray) range(1)) title("CFLs", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("") /*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 2 appliances (mean by village)")*/ legend(off) || lfit cfl_mean grid_meanyrsv, lc(gs12) saving(cfl_mean, replace)
twoway sc fan_mean grid_meanyrsv, mcolor("176 227 202") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray) range(1)) title("Fans", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("") /*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 2 appliances (mean by village)")*/ legend(off) || lfit cfl_mean grid_meanyrsv, lc(gs12) saving(fan_mean, replace)
twoway sc pressure_mean grid_meanyrsv, mcolor("176 227 202") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray) range(1)) title("Pressure cookers", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("") /*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 4 appliances (mean by village)")*/ legend(off) || lfit pressure_mean grid_meanyrsv, lc(gs12) saving(pressure_mean, replace)
twoway sc tvs_mean grid_meanyrsv, mcolor("176 227 202") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray) range(1)) title("TVs", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("") /*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 4 appliances (mean by village)")*/ legend(off) || lfit tvs_mean grid_meanyrsv, lc(gs12) saving(tvs_mean, replace)
twoway sc cooler_mean grid_meanyrsv, mcolor("176 227 202") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray) range(1))	title("Coolers", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("")/*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 1 appliances (mean by village)")*/ legend(off) || lfit cooler_mean grid_meanyrsv, lc(gs12) saving(cooler_mean, replace)
twoway sc fridge_mean grid_meanyrsv, mcolor("176 227 202") graphregion(c(white)) xscale(lc(gray)) yscale(lc(gray) range(1)) title("Refrigerators", color(gray) size(medium)) ytitle(, c(gray) size(small)) xtitle("") /*"Years of electrification (mean by village)", c(gray) size(small))*/ylabel(, labcolor(gray) tlc(gray) nogrid) xlabel(, labcolor(gray) tlc(gray) nogrid) ytitle("") /*"Number of Tier 4 appliances (mean by village)")*/ legend(off) || lfit fridge_mean grid_meanyrsv, lc(gs12) saving(fridge_mean, replace)
graph combine phone_mean.gph cfl_mean.gph fan_mean.gph pressure_mean.gph tvs_mean.gph fridge_mean.gph, xcommon ycommon title("Ownership of key appliances and years since electrification by village", size(medium) c(gray)) graphregion(c(white)) l1("Household appliance ownership (binary ownership average by village)", size(small) color(gray)) b1("Years since electrification (average by village)", size(small) color(gray)) rows(3) cols(2)
graph export, replace

*	************************************************************************
* 	4. Appendix table
*	************************************************************************

* TABLE A6 : Additional sample statistics 			
estpost sum m1_q20_gender decision_f m1_q19_age m1_q22_rw_lang m1_q23_edu m1_q27_no_adults m1_q29_no_children m1_q32_month_expenditure nl_expend				
esttab ., cell((count(label(N)) mean(label(Mean) fmt(2)) sd(label(Std. Dev.) fmt(2)) min(label(Min.) fmt(0)) max(label(Max) fmt(0)))) title("Sample composition") label nomtitle nonumber replace varwidth(25) booktabs noobs
	
	
	
